layui.config({
	base : "js/"
}).use(['form','layer','jquery','layedit','laydate'],function(){
	var form = layui.form(),
		layer = parent.layer === undefined ? layui.layer : parent.layer,
		laypage = layui.laypage,
		layedit = layui.layedit,
		laydate = layui.laydate,
		$ = layui.jquery;

 	var systemParameter;
 	var editIndex = layedit.build('news_content');
 	var orgId = window.sessionStorage.getItem("organizeEditId");
	var memberNum = window.sessionStorage.getItem("memberNumEditId")
	
	var data = {
		orgId:orgId,
		memberNum:memberNum
	}
	var index = layer.load(1, {shade: [0.1, '#fff']}); //0.1透明度的白色背景
	//top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
	getUser(data,function(){
		layer.close(index);
	});
	
 	form.on("submit(subInfo)",function(data){
   		layedit.sync(editIndex);
// 		//弹出loading
 			var mobiles = "";
            var ms = $('[name="mobile"]').length;
            for (var i = 0; i < ms; i++) {
                var mo = $('[name="mobile"]').eq(i).val();
//              if (!reg2.test(mo)) {
//                  errorToast("请输入正确格式的手机号", 3);
//                  return false;
//              }
                if (i == ms - 1) {
                    mobiles += mo;
                } else {
                    $('[name="mobile"]').eq(i).val()
                    mobiles += mo + ",";
                }
            }
		var data={
 			weChat: $(".wechat").val(),
			name: $(".name").val(),
			sex: $(".sex").val(),
			newBirthday: $(".birthday").val(),
			email: $(".email").val(),
			site: $(".site").val(),
			mobiles: mobiles,
			introduce: $("#news_content").val(),
			tel: $(".tel").val()
 		}
   	
   		updateInfo(data,function(){
   			layer.close(index);
   		});
 		return false;
 	})
	
 	

 	//填充数据方法
 	function fillData(data){
 		$(".memberNum").val(data.memberNum);  
 		$(".name").val(data.name); //当前版本
		$(".department").val(data.department);        //开发作者
		$(".profession").val(data.profession);    //网站首页
		$(".mobile").val(data.mobiles[0]);        //服务器环境
		$(".wechat").val(data.weChat);    //数据库版本
		$(".tel").val(data.tel);  //最大上传限制
		$(".email").val(data.email);//当前用户权限
		$(".birthday").val(data.newBirthday);      //模版名称
		$(".site").val(data.site);	//站点描述
		$("#news_content").val(data.introduce);      //版权信息

		$('[name="otype"]').attr("disabled", "disabled");
//		$("input[name=otype][value=0]").attr("checked", true); //设置当前性别选中项
		$("input[name=otype][value=" + data.type + "]").attr("checked", true); //设置当前性别选中项
		form.render('radio');
		
 	}
 function updateInfo(data,callback) {

	console.log('step into registerSubmit()')
	$.ajax({
		url: $.httpRootPath() + "/api/web/member/i/" + orgId + "/" + memberNum,
		type: 'POST',
		dataType: 'json',
		data: data,
		timeout: 15000,
		cache: false,
		success: function(r) {
			if(r.code == "00") {
				layer.msg("更新成功！");
			} else {
				layer.msg("更新失败！");
			}
		},
		error: function(e) {
			layer.msg("系统错误！");
		},
		complete: function() {
			callback();
		}
	});

}

function getUser(data) {
	$.ajax({
		url: $.httpRootPath() + "/api/web/member/i/" + data.orgId + "/" + data.memberNum,
		type: "get",
		dataType: "json",
		data: data,
		success: function(data) {
			if(data.code == "00") {
				fillData(data.data);
			} else {
				layer.msg(data.msg);
			}
		},
		error: function() {
			layer.alert('加载失败', {
				icon: 6,
				title: '友情提示'
			});
		},
		complete: function() {
			callback();
		}
	})

}
})
